package com.github.aloxc.plugin.restplus.i18n;

import com.intellij.CommonBundle;
import kotlin.TypeCastException;
import kotlin.jvm.internal.Intrinsics;
import kotlin.text.StringsKt;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.Locale;
import java.util.ResourceBundle;

public class I18 {
    private static final I18Config CONFIG;
    private static final ResourceBundle RESOURCE_BUNDLE;
//    public static final I18 INSTANCE;

    static {
        I18 bundle = new I18();
        CONFIG = (I18Config) CommonExtensionsKt.getService(I18Config.class);
        RESOURCE_BUNDLE = ResourceBundle.getBundle("messages.i18Bundle",
                new Locale(CONFIG.getLocale()), (ResourceBundle.Control) new XmlControl());
    }

    @NotNull
    public final String getMessage(@NotNull String key) {
        Intrinsics.checkParameterIsNotNull(key, "key");
        Intrinsics.checkExpressionValueIsNotNull(RESOURCE_BUNDLE.getString(key), "resourceBundle.getString(key)");
        String str = RESOURCE_BUNDLE.getString(key);
        boolean bool = false;
        if (str == null){
            throw new TypeCastException("null cannot be cast to non-null type kotlin.CharSequence");
        }
        return StringsKt.trim(str).toString();
    }


    @NotNull
    public final String message(@NotNull String key, @NotNull Object... params) {
        Intrinsics.checkParameterIsNotNull(key, "key");
        Intrinsics.checkParameterIsNotNull(params, "params");
        Intrinsics.checkExpressionValueIsNotNull(CommonBundle.message(RESOURCE_BUNDLE, key, Arrays.copyOf(params, params.length)), "CommonBundle.message(resourceBundle, key, *params)");
        String str = CommonBundle.message(RESOURCE_BUNDLE, key, Arrays.copyOf(params, params.length));
        boolean bool = false;
        if (str == null) {
            throw new TypeCastException("null cannot be cast to non-null type kotlin.CharSequence");
        }
        return StringsKt.trim(str).toString();
    }
}
